// 插件的结构

module.exports = class txtwebpackplugin {
  constructor(options) {
    //接受参数
    console.log(options);
  }
  // apply
  apply(compiler) {
    //钩入hook
    //同步用compiler.hooks.emit.tap
    compiler.hooks.emit.tapAsync("txtwebpackplugin", (compilation, cb) => {
      console.log(compilation.assets);

      compilation.assets["kkb.txt"] = {
        source: function () {
          return "hello txt";
        },
        size: function () {
          return 2;
        },
      };
      cb();
    });
    compiler.hooks.compile.tap("txtwebpackplugin", (compilation) => {
      console.log(compilation.assets);
    });
  }
};
